package com.woniuxy.vuetest.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author linke
 * @version 1.0
 * @className: CorsConfig
 * @description: 全局跨域配置
 * @date 2021/11/18 22:55
 * 跨域解决方式二
 */
//@Configuration
public class CorsConfig implements WebMvcConfigurer {
        static final String[] ORIGINS = new String[] { "GET", "POST", "PUT", "DELETE" };
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry
                    //所有url
                    .addMapping("/**")
                    //所有域
                    .allowedOrigins("*")
                    //运行携带凭证 cookie token
                    .allowCredentials(true)
                    //允许的请求方式
                    .allowedMethods(ORIGINS)
                    //超时时间
                    .maxAge(3600);
        }

}
